package com.github.llyb120.qiuya.storage.bptree;

import java.util.*;

import static com.github.llyb120.qiuya.storage.bptree.BPlusTree.INVALID_OFFSET;
import static com.github.llyb120.qiuya.util.Convert.byte2long;
import static com.github.llyb120.qiuya.util.Convert.longToByteArray;

public final class Node {
    public static final int BLOCK_SIZE = 1024;
    public static final int NEED_TO_SPLIT = -1;
    public static final int ELEMENT_EXISTED = -2;

    //自身所在的文件偏移
    public long self = INVALID_OFFSET;
    //树指针
    public boolean isLeaf = false;

    //最大可以放入的值
    static int max = 3;

    //next所在偏移
    public long next = INVALID_OFFSET;
    public long prev = INVALID_OFFSET;

    public List<NodeData> data = new ArrayList<>();

    Node() {
    }

    public boolean canSplit() {
        return data.size() > max;
    }

    public NodeData getLastData() {
        if (data.isEmpty()) {
            return null;
        }
        return data.get(data.size() - 1);
    }

}
